<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="创建时间" :style="{'fontWeight':'800'}">
        <el-date-picker
          v-model="daterangeCreateTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="datetimerange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="审核状态" prop="status" :style="{'fontWeight':'800'}">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择审核状态"
          clearable
        >
          <el-option
            v-for="dict in dict.type.si_package_audit_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="carPackageAuditList"
      :header-row-style="{'fontWeight':'800'}"
    >
      <el-table-column label="套餐名称" align="center" prop="serviceItemName" />
      <el-table-column
        label="套餐价格"
        align="center"
        prop="serviceItemPrice"
      />
      <el-table-column
        label="套餐备注"
        align="center"
        prop="serviceItemInfo"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="创建时间" align="center" prop="createTime" :show-overflow-tooltip="true"/>
      <el-table-column label="创建者" align="center" prop="creatorNickName" :show-overflow-tooltip="true"/>
      <el-table-column label="备注" align="center" prop="info" :show-overflow-tooltip="true"/>
      <el-table-column label="审核状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.si_package_audit_status"
            :value="scope.row.status"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width" width="200px"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleHistory(scope.row)"
            v-hasPermi="['workflow:carPackageAudit:history']"
            >审批历史</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-info"
            @click="handleProgressImg(scope.row)"
            v-hasPermi="['workflow:carPackageAudit:processImg']"
            >进度查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            v-if="scope.row.status != 6"
            @click="handleDelete(scope.row)"
            v-hasPermi="['workflow:carPackageAudit:cancel']"
            >撤销</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 审批历史按钮对话框 -->
    <el-dialog :title="historyTitle" :visible.sync="historyOpen" width="1000px" append-to-body>
      <el-table
        v-loading="loading"
        :data="historyList"
        :header-row-style="{'fontWeight':'800'}"
      >
      <el-table-column label="任务名称" align="center" prop="activityName" :show-overflow-tooltip="true"/>
      <el-table-column label="开始时间" align="center" prop="startTime" :show-overflow-tooltip="true"/>
      <el-table-column label="结束时间" align="center" prop="endTime" :show-overflow-tooltip="true"/>
      <el-table-column label="耗时" align="center" prop="datePoor" :show-overflow-tooltip="true"/>
      <el-table-column label="审批人" align="center" prop="assignee" :show-overflow-tooltip="true"/>
      <el-table-column label="审批意见" align="center" prop="message" :show-overflow-tooltip="true"/>
      <el-table-column label="撤销理由" align="center" prop="reason" :show-overflow-tooltip="true"/>

      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">关闭</el-button>
      </div>
    </el-dialog>

    <!-- 进度查看 -->
    <el-dialog :title="processImgTitle" :visible.sync="processImgOpen" width="1300px" append-to-body>
      <div v-html="processImg"></div>
    </el-dialog>

    <el-dialog>
    </el-dialog>
  </div>
</template>

<script>
import {
  listCarPackageAudit,
  cancelProcess,
  readProcessImg,
  historyProcess
} from "@/api/workflow/carPackageAudit";

export default {
  name: "CarPackageAudit",
  dicts: ["si_package_audit_status"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 套餐信息表格数据
      carPackageAuditList: [],
      // 审批历史弹出层标题
      historyTitle: "",
      // 审批历史是否显示弹出层
      historyOpen: false,
      // 审批历史记录
      historyList:[],
      // 进度查看弹出层标题
      processImgTitle:"",
      // 进度查看是否显示弹出层
      processImgOpen: false,
      // 审核状态时间范围
      daterangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        status: null,
        createTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      //查看流程进度svg图片
      processImg:{},
      //撤销审核原因
      reason:""
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 审批历史 */
    handleHistory(row){
      this.historyOpen = true;
      this.historyTitle = "审批历史";
      historyProcess(row.instanceId).then(res=>this.historyList = res.rows)
    },
    /** 进度查看 */
    handleProgressImg(row){
      readProcessImg(row.id).then(res=>{
        this.processImgOpen = true;
        this.processImgTitle = "进度查看";
        this.processImg=res
      });
    },

    /** 查询套餐信息列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreateTime && "" != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] =
          this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      listCarPackageAudit(this.queryParams).then((response) => {
        this.carPackageAuditList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.historyOpen = false;
      this.processImgOpen = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 撤销按钮操作 */
    handleDelete(row) {
      const id = row.id || this.ids;
      this.$prompt('是否确认撒销这条审核记录,如果确认请输入撤销理由', '系统提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          inputPattern: /.+/,
          inputErrorMessage: '请输入撤销理由'
        }).then(({ value }) => {
          let formData = new FormData();
          formData.append("id",id);
          formData.append("reason",value)
          cancelProcess(formData).then(res=>{
            this.$message({
              type: 'success',
              message: '撤销成功,撤销理由是: ' + value
            });    
            this.getList();        
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消输入'
          });       
        });
    }
  },
};
</script>
